var Q = require('q');
var _ = require('underscore');
var E = require('../error.js');
var models = {};
//ec模块,链接的是现有的ec数据库
models.ec = require('./ec');
//api模块，链接是的是api数据库
models.api = require('./api');
//erp管理模块
models.erp = require('./erp');
//公共基础模块
models.common = require('./common');
//活动基础模块
models.activity = require('./activity');

models.order = require('./order');

models.job = require('./job');

function defaultHandler(args){
    var deferred = Q.defer();
    deferred.reject(E.System.NOT_METHOD);
    return deferred.promise;
}

module.exports = {
    getFunction:function(method){
        var path = method.split('.');
        var len = path.length;
        var obj = models;
        var handler = defaultHandler;
        var hasFunction = true;
        for(var i = 0;i<len;i++){
            obj = obj[path[i]];
            //handler = obj;
            //未定位到任何的函数
            if(!obj){
                hasFunction = false;
                break;
            }
        }
        if(hasFunction){
            handler = obj;
        }
        return handler;
    }
}